var left;

function init() {
   // alert(1)
    $.ajax({
        type: "post",
        url: ajaxUrl + "/mobile/product/category/getCategory",
        async: true,
        data: {},
        success: function (data) {
            result = data.result;
            var leftStr = "";
            console.log(result);
            for (var i = 0; i < result.length; i++) {
                leftStr += '<li class="menu-left-li " ><span class="text">' + result[i].name + '</span></li>';
            }
            $('#leftList').html(leftStr);
            showRight(result[0].children,result[0].id);

            $('#menuLeft .menu-left-li').click(function (e) {
                var i = $(this).index();
                var t = $('#menuLeft').scrollTop();
                $('#menuLeft .menu-left-li').eq(i).addClass('on').siblings().removeClass('on');
                // ///////////////
                $('#menuLeft').stop().animate({
                    scrollTop: t + $('#menuLeft .menu-left-li').eq(i).offset().top - $('#menuLeft').height() / 2 + $('#menuLeft .menu-left-li').height() * 0.5
                }, 200)
                // 左侧按钮位置垂直居中(不想要直接干掉)

                var children = result[i].children;
                showRight(children,result[i].id);
            })
        }
    });
}

function showRight(children,cid) {
    var rightStr = "";
    for (var i = 0; i < children.length; i++) {
        rightStr += '<a href="more.html?catId='+cid+'&pcatId='+children[i].id+'" class="content-item">';
        rightStr += '<img src="' + children[i].logo + '" alt="" class="icon">';
        rightStr += '<div class="text">'+children[i].name+'</div></a>';
    }

    $('#rightList').html(rightStr);
}